/**
 * 2009 David BY Chan--lifesting@gmail.com
 *
 * $Id$
 */
package com.lifesting.workflow.model.gd.impl;

import com.lifesting.workflow.model.gd.CreateTimerType;
import com.lifesting.workflow.model.gd.Decision;
import com.lifesting.workflow.model.gd.End;
import com.lifesting.workflow.model.gd.Esb;
import com.lifesting.workflow.model.gd.Fork;
import com.lifesting.workflow.model.gd.GdPackage;
import com.lifesting.workflow.model.gd.Join;
import com.lifesting.workflow.model.gd.Mail;
import com.lifesting.workflow.model.gd.ProcessState;
import com.lifesting.workflow.model.gd.Start;
import com.lifesting.workflow.model.gd.State;

import com.lifesting.workflow.model.gd.SuperState;
import com.lifesting.workflow.model.gd.TaskContainer;
import com.lifesting.workflow.model.gd.WebService;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.BasicFeatureMap;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Process</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getStart <em>Start</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getWorkflowDefinition <em>Workflow Definition</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getState <em>State</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getJoin <em>Join</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getFork <em>Fork</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getDecision <em>Decision</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getSuperState <em>Super State</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getProcessState <em>Process State</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getMail <em>Mail</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getEsb <em>Esb</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getWsNode <em>Ws Node</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getTaskNode <em>Task Node</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getEnd <em>End</em>}</li>
 *   <li>{@link com.lifesting.workflow.model.gd.impl.ProcessImpl#getCreateTimer <em>Create Timer</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProcessImpl extends GraphElementImpl implements com.lifesting.workflow.model.gd.Process {
	/**
	 * The cached value of the '{@link #getStart() <em>Start</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStart()
	 * @generated
	 * @ordered
	 */
	protected Start start;

	/**
	 * The cached value of the '{@link #getWorkflowDefinition() <em>Workflow Definition</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWorkflowDefinition()
	 * @generated
	 * @ordered
	 */
	protected FeatureMap workflowDefinition;

	/**
	 * The cached value of the '{@link #getEnd() <em>End</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEnd()
	 * @generated
	 * @ordered
	 */
	protected End end;

	/**
	 * The cached value of the '{@link #getCreateTimer() <em>Create Timer</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCreateTimer()
	 * @generated
	 * @ordered
	 */
	protected EList<CreateTimerType> createTimer;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProcessImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GdPackage.Literals.PROCESS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Start getStart() {
		return start;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetStart(Start newStart, NotificationChain msgs) {
		Start oldStart = start;
		start = newStart;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS__START, oldStart, newStart);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStart(Start newStart) {
		if (newStart != start) {
			NotificationChain msgs = null;
			if (start != null)
				msgs = ((InternalEObject)start).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS__START, null, msgs);
			if (newStart != null)
				msgs = ((InternalEObject)newStart).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS__START, null, msgs);
			msgs = basicSetStart(newStart, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS__START, newStart, newStart));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureMap getWorkflowDefinition() {
		if (workflowDefinition == null) {
			workflowDefinition = new BasicFeatureMap(this, GdPackage.PROCESS__WORKFLOW_DEFINITION);
		}
		return workflowDefinition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<State> getState() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__STATE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Join> getJoin() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__JOIN);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Fork> getFork() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__FORK);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Decision> getDecision() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__DECISION);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SuperState> getSuperState() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__SUPER_STATE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ProcessState> getProcessState() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__PROCESS_STATE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Mail> getMail() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__MAIL);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Esb> getEsb() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__ESB);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<TaskContainer> getTaskNode() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__TASK_NODE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<WebService> getWsNode() {
		return getWorkflowDefinition().list(GdPackage.Literals.PROCESS__WS_NODE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public End getEnd() {
		return end;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEnd(End newEnd, NotificationChain msgs) {
		End oldEnd = end;
		end = newEnd;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS__END, oldEnd, newEnd);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEnd(End newEnd) {
		if (newEnd != end) {
			NotificationChain msgs = null;
			if (end != null)
				msgs = ((InternalEObject)end).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS__END, null, msgs);
			if (newEnd != null)
				msgs = ((InternalEObject)newEnd).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS__END, null, msgs);
			msgs = basicSetEnd(newEnd, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS__END, newEnd, newEnd));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CreateTimerType> getCreateTimer() {
		if (createTimer == null) {
			createTimer = new EObjectContainmentEList<CreateTimerType>(CreateTimerType.class, this, GdPackage.PROCESS__CREATE_TIMER);
		}
		return createTimer;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GdPackage.PROCESS__START:
				return basicSetStart(null, msgs);
			case GdPackage.PROCESS__WORKFLOW_DEFINITION:
				return ((InternalEList<?>)getWorkflowDefinition()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__STATE:
				return ((InternalEList<?>)getState()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__JOIN:
				return ((InternalEList<?>)getJoin()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__FORK:
				return ((InternalEList<?>)getFork()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__DECISION:
				return ((InternalEList<?>)getDecision()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__SUPER_STATE:
				return ((InternalEList<?>)getSuperState()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__PROCESS_STATE:
				return ((InternalEList<?>)getProcessState()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__MAIL:
				return ((InternalEList<?>)getMail()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__ESB:
				return ((InternalEList<?>)getEsb()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__WS_NODE:
				return ((InternalEList<?>)getWsNode()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__TASK_NODE:
				return ((InternalEList<?>)getTaskNode()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS__END:
				return basicSetEnd(null, msgs);
			case GdPackage.PROCESS__CREATE_TIMER:
				return ((InternalEList<?>)getCreateTimer()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GdPackage.PROCESS__START:
				return getStart();
			case GdPackage.PROCESS__WORKFLOW_DEFINITION:
				if (coreType) return getWorkflowDefinition();
				return ((FeatureMap.Internal)getWorkflowDefinition()).getWrapper();
			case GdPackage.PROCESS__STATE:
				return getState();
			case GdPackage.PROCESS__JOIN:
				return getJoin();
			case GdPackage.PROCESS__FORK:
				return getFork();
			case GdPackage.PROCESS__DECISION:
				return getDecision();
			case GdPackage.PROCESS__SUPER_STATE:
				return getSuperState();
			case GdPackage.PROCESS__PROCESS_STATE:
				return getProcessState();
			case GdPackage.PROCESS__MAIL:
				return getMail();
			case GdPackage.PROCESS__ESB:
				return getEsb();
			case GdPackage.PROCESS__WS_NODE:
				return getWsNode();
			case GdPackage.PROCESS__TASK_NODE:
				return getTaskNode();
			case GdPackage.PROCESS__END:
				return getEnd();
			case GdPackage.PROCESS__CREATE_TIMER:
				return getCreateTimer();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GdPackage.PROCESS__START:
				setStart((Start)newValue);
				return;
			case GdPackage.PROCESS__WORKFLOW_DEFINITION:
				((FeatureMap.Internal)getWorkflowDefinition()).set(newValue);
				return;
			case GdPackage.PROCESS__STATE:
				getState().clear();
				getState().addAll((Collection<? extends State>)newValue);
				return;
			case GdPackage.PROCESS__JOIN:
				getJoin().clear();
				getJoin().addAll((Collection<? extends Join>)newValue);
				return;
			case GdPackage.PROCESS__FORK:
				getFork().clear();
				getFork().addAll((Collection<? extends Fork>)newValue);
				return;
			case GdPackage.PROCESS__DECISION:
				getDecision().clear();
				getDecision().addAll((Collection<? extends Decision>)newValue);
				return;
			case GdPackage.PROCESS__SUPER_STATE:
				getSuperState().clear();
				getSuperState().addAll((Collection<? extends SuperState>)newValue);
				return;
			case GdPackage.PROCESS__PROCESS_STATE:
				getProcessState().clear();
				getProcessState().addAll((Collection<? extends ProcessState>)newValue);
				return;
			case GdPackage.PROCESS__MAIL:
				getMail().clear();
				getMail().addAll((Collection<? extends Mail>)newValue);
				return;
			case GdPackage.PROCESS__ESB:
				getEsb().clear();
				getEsb().addAll((Collection<? extends Esb>)newValue);
				return;
			case GdPackage.PROCESS__WS_NODE:
				getWsNode().clear();
				getWsNode().addAll((Collection<? extends WebService>)newValue);
				return;
			case GdPackage.PROCESS__TASK_NODE:
				getTaskNode().clear();
				getTaskNode().addAll((Collection<? extends TaskContainer>)newValue);
				return;
			case GdPackage.PROCESS__END:
				setEnd((End)newValue);
				return;
			case GdPackage.PROCESS__CREATE_TIMER:
				getCreateTimer().clear();
				getCreateTimer().addAll((Collection<? extends CreateTimerType>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GdPackage.PROCESS__START:
				setStart((Start)null);
				return;
			case GdPackage.PROCESS__WORKFLOW_DEFINITION:
				getWorkflowDefinition().clear();
				return;
			case GdPackage.PROCESS__STATE:
				getState().clear();
				return;
			case GdPackage.PROCESS__JOIN:
				getJoin().clear();
				return;
			case GdPackage.PROCESS__FORK:
				getFork().clear();
				return;
			case GdPackage.PROCESS__DECISION:
				getDecision().clear();
				return;
			case GdPackage.PROCESS__SUPER_STATE:
				getSuperState().clear();
				return;
			case GdPackage.PROCESS__PROCESS_STATE:
				getProcessState().clear();
				return;
			case GdPackage.PROCESS__MAIL:
				getMail().clear();
				return;
			case GdPackage.PROCESS__ESB:
				getEsb().clear();
				return;
			case GdPackage.PROCESS__WS_NODE:
				getWsNode().clear();
				return;
			case GdPackage.PROCESS__TASK_NODE:
				getTaskNode().clear();
				return;
			case GdPackage.PROCESS__END:
				setEnd((End)null);
				return;
			case GdPackage.PROCESS__CREATE_TIMER:
				getCreateTimer().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GdPackage.PROCESS__START:
				return start != null;
			case GdPackage.PROCESS__WORKFLOW_DEFINITION:
				return workflowDefinition != null && !workflowDefinition.isEmpty();
			case GdPackage.PROCESS__STATE:
				return !getState().isEmpty();
			case GdPackage.PROCESS__JOIN:
				return !getJoin().isEmpty();
			case GdPackage.PROCESS__FORK:
				return !getFork().isEmpty();
			case GdPackage.PROCESS__DECISION:
				return !getDecision().isEmpty();
			case GdPackage.PROCESS__SUPER_STATE:
				return !getSuperState().isEmpty();
			case GdPackage.PROCESS__PROCESS_STATE:
				return !getProcessState().isEmpty();
			case GdPackage.PROCESS__MAIL:
				return !getMail().isEmpty();
			case GdPackage.PROCESS__ESB:
				return !getEsb().isEmpty();
			case GdPackage.PROCESS__WS_NODE:
				return !getWsNode().isEmpty();
			case GdPackage.PROCESS__TASK_NODE:
				return !getTaskNode().isEmpty();
			case GdPackage.PROCESS__END:
				return end != null;
			case GdPackage.PROCESS__CREATE_TIMER:
				return createTimer != null && !createTimer.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (workflowDefinition: ");
		result.append(workflowDefinition);
		result.append(')');
		return result.toString();
	}

} //ProcessImpl
